package com.eliza.base.views.learn.animation

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController

@Preview(showBackground = true)
@Composable
fun LearnAnimationScreenPre() {
    LearnAnimationScreen(rememberNavController())
}

@Composable
fun LearnAnimationScreen(it: NavController) {
    AnimationContentShowX()
    //        ============
}

@Composable
private fun AnimationContentShowX() {
    var state by remember {
        mutableStateOf(0)
    }
    AnimatedContent(
        state, transitionSpec = {
            fadeIn(
                animationSpec = tween(1000)
            ) togetherWith
                    fadeOut(animationSpec = tween(100))
        },
        modifier = Modifier.clickable(
            interactionSource = remember { MutableInteractionSource() },
            indication = null
        ) {
            state = (state + 1) % 7
        }, label = "Change Animated Content"
    ) { targetState ->
        Column {
            Text(text = "Click To Change $targetState", modifier = Modifier.background(Color.Gray))
            when (targetState) {
                0 -> BasicAnimationX.Show()
                1 -> AnimateValueX.Show()
                2 -> AnimateValueLowX.Show()
                3 -> AnimationModifierX.Show()
                4 -> AnimationVectorsX.Show()
                5 -> AnimationCustomizeX.Show()
                6 -> AnimationAdvancedX.Show()
            }
        }
    }
}

enum class UiState {
    Visible,
    Position,
    PositionX,
    Text,
    RepeatX,
    LaunchedX,
}

enum class BoxState {
    Collapsed,
    Expanded,
}
